static int s[10000000];main(t,n,b,i,w,l){*s=1;for(b=i=w=l=n=0;n<1e7;n++){if(s[b]*3==s[w]*2)b++;if(s[b]*3<s[w]*2)s[++l]=s[b++]*3+1;else s[++l]=s[w++]*2+1;}for(gets(&t);~scanf("%d",&n);printf("%d\n",s[n-1]));}
